package service

import (
	"project/PersonalBlog/dao/db"
	"project/PersonalBlog/model"
)

//GetArticleRecord ..获取文章和对应的分类
func GetArticleRecord(page int64) (article []*model.ArticleInfo) {
	article = db.GetArticleList(page)
	for _, v := range article {
		v.CategoryName = GetCategoryNameByID(v.CategoryID)
		//fmt.Println("---->", v.CreateTime)
	}
	return
}

//GetCategoryArticle ..获取分类文章
func GetCategoryArticle(id int32) (article []*model.ArticleInfo) {
	article = db.GetSimilarArticles(id)
	for _, v := range article {
		v.CategoryName = GetCategoryNameByID(v.CategoryID)
		//fmt.Println("---->", v.CreateTime)
	}
	return
}

//GetArticleContext ..拉取文章详细内容
func GetArticleContext(id int64) (article *model.ArticleDetail) {
	article = db.GetArticle(id)
	article.CategoryName = GetCategoryNameByID(article.ArticleInfo.CategoryID)
	return
}

//GetArticlePN ..拉取文章上下文文
func GetArticlePN(id int64) (record []*model.ArticleRecord) {
	record = append(record, &model.ArticleRecord{})
	record = append(record, &model.ArticleRecord{})
	prev := db.GetArticle(id - 1)
	if prev != nil {
		record[0].ArticleID = prev.ID
		record[0].Title = prev.Title
	} else {
		record[0].ArticleID = -1
	}
	next := db.GetArticle(id + 1)
	if next != nil {
		record[1].ArticleID = next.ID
		record[1].Title = next.Title
	} else {
		record[1].ArticleID = -1
	}
	return
}

//InputArticle 插入文章
func InputArticle(article *model.ArticleDetail) (id int64) {
	return db.InsertArticle(article)
}
